﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _05原型设计模式
{
    public class Resume:ICloneable
    {
        public string ? Name { get; set; }
        public int Age { get; set; }
        public char Gender { get; set; }
        //public string  TimeArea { get; set; }
        //public string  Company { get; set; }
        //引用类型
        public WorkExperience workExperience;
        public Resume()
        {
            this.workExperience = new WorkExperience(); 
        }
        private Resume(WorkExperience workExperience)
        { 
            this.workExperience=(WorkExperience)workExperience.Clone(); 
        }
        public object Clone()
        {
            //在创建新对象的时候把工作经验这个引用类型也复制一份
            
            Resume resume = new Resume(this.workExperience);  
            resume.Name = this.Name;
            resume.Age = this.Age;  
            resume.Gender = this.Gender;    
            return resume;

            //如果依然调用this.MemberwiseClone();引用类型，就永远不可能被复制一份新的
            //return this.MemberwiseClone(); //这种写法只能拷贝值类型
        }
        public void SetInfo(string name, int age, char gender)
        {
            Name = name;
            Age=age;
            Gender=gender;
        }
        public void SetWorkExperience(string timeArea, string company)
        {
            //TimeArea = timeArea;
            //Company=company;
            this.workExperience.TimeArea = timeArea;
            this.workExperience.Company = company;
        }
        public void ShowResume()
        {
            Console.WriteLine($"{this.Name},{this.Age},{this.Gender}");
            Console.WriteLine($"{this.workExperience.TimeArea},{this.workExperience.Company}");
        }
    }

    public class WorkExperience:ICloneable
    {
        public string ?TimeArea { get; set; }
        public string? Company { get; set; }

        public object Clone()
        {
          return  this.MemberwiseClone();
        }
    }
}
